package com.stg.controller;


import java.util.List;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stg.bean.Assn;
import com.stg.bean.Message;
import com.stg.bean.Msg;
import com.stg.bean.Student;
import com.stg.bean.User;
import com.stg.service.StudentService;
import com.stg.service.UserService;

@Controller
@RequestMapping("/student")
public class StudentController {
	
	@Resource
	private StudentService studentService;
	
	@Resource
	private UserService userService;
	
	@Resource
	private Msg msg;
	
	
	@RequestMapping(value="/studentMessagePost",method=RequestMethod.POST)
	public @ResponseBody Msg studentMessagePost (Model model,Student student){
		studentService.createStudent(student);
		msg.setMsg("学生信息录入成功");
		return msg;
	}
	
	@RequestMapping(value="/studentMessageInfo",method=RequestMethod.GET)
	public String studentMessageInfo(Model model){
		Subject subject = SecurityUtils.getSubject();
        String username = subject.getPrincipal().toString();
        User user = userService.findByUsername(username);
        
		Student student = studentService.findStudentById(user.getstudentId());
		model.addAttribute("student", student);
		model.addAttribute("active", "studentMessageInfo");
		return "/student/studentMessageInfo";
	}
	
	@RequestMapping(value="/studentAssn",method=RequestMethod.GET)
	public String findStudentAssn(Model model){
		Subject subject = SecurityUtils.getSubject();
        String username = subject.getPrincipal().toString();
        User user = userService.findByUsername(username);
        
		List<Assn> attentionAssn = studentService.findAllAssnAttentionByStudentId(user.getstudentId());
		List<Assn> pendedAssn = studentService.findAllAssnPendedByStudentId(user.getstudentId());
		List<Assn> pendingAssn = studentService.findAllAssnPendingByStudentId(user.getstudentId());
		model.addAttribute("attentionAssn", attentionAssn);
		model.addAttribute("pendedAssn", pendedAssn);
		model.addAttribute("pendingAssn", pendingAssn);
		model.addAttribute("active", "findStudentAssn");
		return "/student/studentAssn";
	}
	
	@RequestMapping(value="/studentMessageReceive",method=RequestMethod.GET)
	public String studentMessageReceive(Model model){
		Subject subject = SecurityUtils.getSubject();
        String username = subject.getPrincipal().toString();
        User user = userService.findByUsername(username);
        Student student = studentService.findStudentById(user.getstudentId());
        
		List<Message> messageList =  studentService.studentMessageReceive(student.getId());
		model.addAttribute("messageList", messageList);
		model.addAttribute("active", "studentMessageReceive");
		return "/student/studentMessageReceive";
	}
	
	@RequestMapping(value="/studentMessageDetail",method=RequestMethod.GET)
	public String studentMessageDetail(Model model,int assnId){
		
		
		return "";
	}
}
